<template>
 <div class="borrower">

    <el-card class="box-card" shadow="never" style="border:0px;">
      <!-- 查询结果 -->
    <el-table  :data="tableDataRow" size="small" element-loading-text="正在查询中。。。" :header-cell-style="{background:'#F7F7F8',color:'#606266'}" fit 
    row-key="id"
    @select="handleSelection"
    @selection-change="handleSelectionChange"
    ref="multipleTable"
    >
      <el-table-column
        type="selection"
        width="55"
        :selectable='selectInit'>
      </el-table-column>
      <el-table-column align="center" label="资方" prop="capitalName" />
      <el-table-column align="center" label="产品名称" prop="productName"/>
      <el-table-column align="center" v-if="pledgeType == 1 || pledgeType == 3" label="利率" prop="oneBetRate"/>
      <el-table-column align="center" v-else label="利率" prop="twoBetRate"/>
      <el-table-column align="center" label="准入情况" prop="checkStatus">
        <template v-slot="{ row }">
          <span :class="!row.checkStatus?'col-red':''">{{row.checkStatus?'准入':'不准入'}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="不准入原因" prop="checkFailReason" min-width="180">
        <template v-slot="{ row }">
          <span>{{row.checkStatus?'-':row.checkFailReason}}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right">
        <template v-slot="{ row }">
          <el-button type="text" @click="seeDetail(row)">准入检测详情</el-button>
        </template>
      </el-table-column>
      
    </el-table>
    </el-card>
    <!-- 对话框 -->
    <el-dialog title="资方+产品+检测详情" :visible.sync="dialogVisible" :close-on-click-modal="false" >
      
      <el-table height="500" border  :data="rowDateil" size="small" element-loading-text="正在查询中。。。" :header-cell-style="{background:'#F7F7F8',color:'#606266'}" fit highlight-current-row>
        <el-table-column
          type="index"
          align="center"
          width="50">
        </el-table-column>
        <el-table-column align="center" label="要素" prop="ruleName" />
        <el-table-column align="center" label="范围" prop="scope" min-width="200"/>
        <el-table-column align="center" label="客户信息" prop="customerInput"/>
        <el-table-column align="center" label="检测情况" prop="checkResult" >
          <template v-slot="{ row }">
            <span :class="row.checkResult == '通过'?'':'col-red'">{{row.checkResult}}</span>
          </template>
        </el-table-column>
        
      </el-table>
      
    </el-dialog>
  </div>
</template>

<style>
  .demo-image__preview{
    width: 100px;
    height: 100px;
    margin:0 auto;
  }
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #20a0ff;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 120px;
    height: 120px;
    line-height: 120px;
    text-align: center;
  }
  .avatar {
    width: 145px;
    height: 145px;
    display: block;
  }
  .col-red{
    color:red;
  }
</style>

<script>
import { mapGetters } from 'vuex';
import { getToken } from '@/utils/auth'
export default {
  name: 'capital',
  // 接受父组件的值
  props: {
     changeValue: undefined,
     projectId: undefined,
     projectStatus: undefined,
     operationLook: undefined,
     taskId: undefined,
     tableData:{
       type: Array,
       default:[]
     }
    },
  data() {
    return {
      defaultProjectId: undefined,
      pledgeType:undefined,
      dialogVisible:false,
      rowDateil:[],
      multipleSelection:[],
      tableDataRow:[]
    }
  },
  computed: {
    ...mapGetters(['roles']),
    headers() {
      return {
        'Authorization': "Bearer-"+getToken()
      }
    }
  },
  watch:{
    tableData(newVal) {
      this.tableDataRow = newVal
       setTimeout(()=>{
        this.tableDataRow.map(item => {
          if(item.selectedStatus){
            this.$refs.multipleTable.toggleRowSelection(item,true);
          }
        })
      },100)
    }
  },
  created() {
    if( this.projectId === undefined ) {
      this.defaultProjectId = localStorage.getItem("projectId")
    }else{
      this.defaultProjectId = this.projectId
    }
    this.pledgeType = localStorage.getItem("pledgeType")
  },
  methods: {
    selectInit(row,index) {
       if(row.checkStatus){
            return true //可勾选
        }else{    
            return false  //不可勾选
        }
    },
      seeDetail(row) {
        this.dialogVisible = true
        this.rowDateil = row.matchDetailDTOS
      },
      
      handleSelectionChange(val) {
        this.multipleSelection = val;
        this.$emit("capitalChange",val)
      },
      handleSelection(select,row) {
        console.log(select,row)
        
      }
  }
}
</script>
